//
//  CellDataModel.swift
//  SinaWb
//
//  Created by Jiang on 5/22/16.
//  Copyright © 2016 Jiang. All rights reserved.
//

import UIKit

class CellDataModel: NSObject {
    
//    static let sharCellDataModel = CellDataModel()

    //微博作者的用户信息字段
    var UserInfo: UserModel?
    
    var id : AnyObject?
    //微博信息内容
    var text : String?
    
    var source: String?
    
    var created_at: String?
   
    //是否已收藏，true：是，false：否
    var favorited :AnyObject?
   
    //缩略图片地址，没有时不返回此字段
    var thumbnail_pic: String?
   
     //配图数组
    var pic_urls:[[String : String]]?
   
    //中等尺寸图片地址，没有时不返回此字段
    var bmiddle_pic : String?
   
    //原始图片地址，没有时不返回此字段
    var original_pic: String?
    
    //地理信息字段
    var geo : AnyObject?
    
    //转发微博
    var  retweeted_status : CellDataModel?
    
    //转发数
    var reposts_count : AnyObject?
    
    //评论数
    var comments_count: AnyObject?
   
    //表态数
    var attitudes_count :AnyObject?
    
    //微博配图ID。多图时返回多图ID，用来拼接图片url。用返回字段thumbnail_pic的地址配上该返回字段的图片ID，即可得到多个图片url。
    var pic_ids : AnyObject?
   
    var originalDic : [String : AnyObject]?
    
    override init() {
        super.init()
    }
    
    init(dictionary:[String : AnyObject]){
        super.init()
        originalDic = dictionary
        setValuesForKeysWithDictionary(dictionary)
        //应为使用了单例，所以就算当字典中retweeted_status不存在时，此时单例中retweeted仍有值，地址为上个一个转发微博的retweeted的地址，所以在赋值前应该先将retweeted设为nil
        if dictionary["retweeted_status"] ==  nil{
            retweeted_status = nil
        }
    }
    
    override func setValue(value: AnyObject?, forKey key: String) {
        super.setValue(value, forKey: key)
        if key == "user" {
            originalDic?.removeValueForKey("user")
            if let dic = value as? [String : AnyObject]{
                UserInfo = UserModel(dictionary: dic)
            }
        }
        
        if key == "retweeted_status" {
            
            retweeted_status = CellDataModel(dictionary: value  as! [String  : AnyObject])
            
            return
        }
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {

    }
    
    override var description: String{
        print("_______________")
        print(originalDic!)
        print("______________")
        print(UserInfo!)
        return " "
    }
}
